/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.dess.mybatis.plugins.execute;

import com.znlh.demo.mybatisdemo.thread.ThreadContextHolder;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.mapping.StatementType;

import java.util.Map;

/**
 * @project-name:dess
 * @package-name:com.hyts.dess.mybatis.interceptor
 * @author:LiBo/Alex
 * @create-date:2020-06-15 12:59
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class CustomExecutorUtils {

    /**
     * 创建对象操作处理器
     *
     * @return
     */
    public static CustomExecutorObject createBean() {
        Map<String, Object> threadContextValue = ThreadContextHolder.getValue(CustomExecutorContext.getTHREAD_LOCAL_EXECUTOR_CONTEXT());
        //条件属性字段
        String conditionKey = String.valueOf(threadContextValue.get(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_KEY));
        // 条件具体值，可以属于具体值 也可以属于固定接口
        String conditionValue = String.valueOf(threadContextValue.get(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_VALUE));
        // 条件具体对象，主要用于处理和植入
        String conditionToken = String.valueOf(threadContextValue.get(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_TOKEN));
        String conditionCallType = String.valueOf(threadContextValue.get(CustomExecutorConstant.DEFAULT_EXECUTOR_CALLER_TYPE));
        Object conditionSubject = threadContextValue.get(CustomExecutorConstant.DEFAULT_EXECUTOR_CONTEXT_SUBJECT);
        return new CustomExecutorObject(conditionKey, conditionValue,conditionToken,conditionCallType,conditionSubject);
    }

    /**
     * 判断是否属于select查询条件语句
     *
     * @param mappedStatement
     * @return
     */
    public static boolean isSelectSql(MappedStatement mappedStatement) {
        return SqlCommandType.SELECT == mappedStatement.getSqlCommandType() && StatementType.CALLABLE != mappedStatement.getStatementType();
    }
}








































































